package com.jxm.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jxm.exception.ApiInvokeException;
import com.jxm.vo.IResult;
/**
 * 统一异常处理 拦截器
 * @author dell
 *
 */
public class ExceptionInterceptor implements Interceptor {

	@Override
	public void intercept(Invocation inv) {
		System.out.println("Before method invoking");
		try {
			inv.invoke();
		} catch (Exception e) {
			e.printStackTrace();
			if(e instanceof ApiInvokeException){
				ApiInvokeException a = (ApiInvokeException)e;
				inv.getController().renderJson(IResult.failed(a.getErrCode(),a.getErrMsg()));
			}
			
		}
       System.out.println("After method invoking");
	}

}
